﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using Confucius.utils;

namespace Confucius.entity
{
    /// <summary>
    /// Author:Liangchuan Gu
    /// date:2012-04-08
    /// </summary>
    public class NPC
    {
        private string npcID;

        public string NpcID
        {
            get { return npcID; }
            set { npcID = value; }
        }

        private string iconID;

        public string IconID
        {
            get
            {
                if (iconID == null)
                {
                    return figureID;
                }
                else
                {
                    return iconID;
                }
            }
            set { iconID = value; }
        }

        private string greeting;

        public string Greeting
        {
            get { return greeting; }
            set { greeting = value; }
        }

        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string chattable;

        public string Chattable
        {
            get { return chattable; }
            set { chattable = value; }
        }

        private string locationID;

        public string LocationID
        {
            get { return locationID; }
            set { locationID = value; }
        }

        private string dialogID;

        public string DialogID
        {
            get { return dialogID; }
            set { dialogID = value; }
        }

        private string figureID;

        public string FigureID
        {
            get { return figureID; }
            set { figureID = value; }
        }

        private float lat;

        public float Lat
        {
            get { return lat; }
            set { lat = value; }
        }

        private float lng;

        public float Lng
        {
            get { return lng; }
            set { lng = value; }
        }

        public const string NOT_CHATTABLE = "f";
        public const string CHATTABLE = "t";
        public const string END_CHAT = "e";

        public string IconUri
        {
            get
            {
                if (iconID == null || iconID.Equals("null"))
                {
                    return "/Confucius;component/assets/images/npc.png";
                }
                else
                {
                    string[] idString = iconID.Split('.');
                    if (idString.Length < 2)
                    {
                        if (IsolatedStorageSettings.ApplicationSettings.Contains(Constants.CURRENT_GAMEID))
                        {
                            string gameID = (string)IsolatedStorageSettings.ApplicationSettings[Constants.CURRENT_GAMEID];
                            return "/Confucius;component/assets/gameFiles/" + gameID + "/" + iconID + ".png";
                        }
                        else
                            return "/Confucius;component/assets/images/npc.png";
                    }
                    else
                    {
                        if (IsolatedStorageSettings.ApplicationSettings.Contains(Constants.CURRENT_GAMEID))
                        {
                            string gameID = (string)IsolatedStorageSettings.ApplicationSettings[Constants.CURRENT_GAMEID];
                            return "/Confucius;component/assets/gameFiles/" + gameID + "/" + iconID;
                        }
                        else
                            return "/Confucius;component/assets/images/npc.png";
                    }
                }
            }
        }

        public Visibility ListVisibility
        {
            get
            {
                if (chattable.Equals(CHATTABLE))
                    return Visibility.Visible;
                else
                    return Visibility.Collapsed;
            }
        }

        public string ChattableToText
        {
            get
            {
                if (chattable.Equals(CHATTABLE))
                    return "Chattable  ";
                else if (chattable.Equals(NOT_CHATTABLE))
                    return "Not Chattable  ";
                else
                    return "Chatted  ";
            }
        }

        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return false;
            }

            // If parameter cannot be cast to this class return false.
            NPC p = obj as NPC;
            if ((System.Object)p == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (npcID == p.npcID) && (chattable == p.chattable);
        }

        public override int GetHashCode()
        {
            return npcID.GetHashCode() * (chattable.GetHashCode());
        }
    }
}
